from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-01 14:07:25.875607
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 01, Feb, 2021
Time: 14:07:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7203
Nobs: 189.000 HQIC: -46.6386
Log likelihood: 2142.83 FPE: 2.97790e-21
AIC: -47.2640 Det(Omega_mle): 1.87235e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.457821 0.143106 3.199 0.001
L1.Burgenland 0.100505 0.074366 1.351 0.177
L1.Kärnten -0.225087 0.061762 -3.644 0.000
L1.Niederösterreich 0.124674 0.172515 0.723 0.470
L1.Oberösterreich 0.235759 0.150839 1.563 0.118
L1.Salzburg 0.202645 0.079972 2.534 0.011
L1.Steiermark 0.091430 0.107721 0.849 0.396
L1.Tirol 0.157584 0.072006 2.188 0.029
L1.Vorarlberg -0.004840 0.065829 -0.074 0.941
L1.Wien -0.126916 0.144788 -0.877 0.381
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.498103 0.177089 2.813 0.005
L1.Burgenland 0.019675 0.092026 0.214 0.831
L1.Kärnten 0.369109 0.076428 4.829 0.000
L1.Niederösterreich 0.119527 0.213482 0.560 0.576
L1.Oberösterreich -0.154063 0.186658 -0.825 0.409
L1.Salzburg 0.191350 0.098963 1.934 0.053
L1.Steiermark 0.240175 0.133302 1.802 0.072
L1.Tirol 0.138473 0.089105 1.554 0.120
L1.Vorarlberg 0.176961 0.081461 2.172 0.030
L1.Wien -0.587478 0.179170 -3.279 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300421 0.063378 4.740 0.000
L1.Burgenland 0.110563 0.032935 3.357 0.001
L1.Kärnten -0.024472 0.027353 -0.895 0.371
L1.Niederösterreich 0.066198 0.076402 0.866 0.386
L1.Oberösterreich 0.289294 0.066802 4.331 0.000
L1.Salzburg 0.006509 0.035417 0.184 0.854
L1.Steiermark -0.023009 0.047707 -0.482 0.630
L1.Tirol 0.093552 0.031889 2.934 0.003
L1.Vorarlberg 0.107758 0.029154 3.696 0.000
L1.Wien 0.078508 0.064122 1.224 0.221
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219716 0.072081 3.048 0.002
L1.Burgenland -0.011248 0.037457 -0.300 0.764
L1.Kärnten 0.022674 0.031109 0.729 0.466
L1.Niederösterreich 0.032429 0.086894 0.373 0.709
L1.Oberösterreich 0.389529 0.075976 5.127 0.000
L1.Salzburg 0.097022 0.040281 2.409 0.016
L1.Steiermark 0.182214 0.054258 3.358 0.001
L1.Tirol 0.041763 0.036268 1.151 0.250
L1.Vorarlberg 0.088247 0.033157 2.661 0.008
L1.Wien -0.064472 0.072928 -0.884 0.377
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.521928 0.144088 3.622 0.000
L1.Burgenland 0.071654 0.074877 0.957 0.339
L1.Kärnten 0.008500 0.062186 0.137 0.891
L1.Niederösterreich -0.012196 0.173699 -0.070 0.944
L1.Oberösterreich 0.157555 0.151874 1.037 0.300
L1.Salzburg 0.059586 0.080521 0.740 0.459
L1.Steiermark 0.109113 0.108461 1.006 0.314
L1.Tirol 0.211080 0.072500 2.911 0.004
L1.Vorarlberg 0.023005 0.066281 0.347 0.729
L1.Wien -0.138691 0.145782 -0.951 0.341
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161964 0.102096 1.586 0.113
L1.Burgenland -0.017781 0.053055 -0.335 0.738
L1.Kärnten -0.014391 0.044063 -0.327 0.744
L1.Niederösterreich 0.126468 0.123077 1.028 0.304
L1.Oberösterreich 0.394070 0.107612 3.662 0.000
L1.Salzburg -0.024038 0.057055 -0.421 0.674
L1.Steiermark -0.032080 0.076851 -0.417 0.676
L1.Tirol 0.190426 0.051371 3.707 0.000
L1.Vorarlberg 0.037257 0.046964 0.793 0.428
L1.Wien 0.185787 0.103296 1.799 0.072
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.232125 0.130473 1.779 0.075
L1.Burgenland 0.078986 0.067801 1.165 0.244
L1.Kärnten -0.043515 0.056310 -0.773 0.440
L1.Niederösterreich -0.022286 0.157286 -0.142 0.887
L1.Oberösterreich -0.102123 0.137523 -0.743 0.458
L1.Salzburg 0.033143 0.072913 0.455 0.649
L1.Steiermark 0.388975 0.098212 3.961 0.000
L1.Tirol 0.494756 0.065649 7.536 0.000
L1.Vorarlberg 0.162811 0.060018 2.713 0.007
L1.Wien -0.220848 0.132007 -1.673 0.094
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080253 0.158401 0.507 0.612
L1.Burgenland 0.036026 0.082314 0.438 0.662
L1.Kärnten -0.093008 0.068363 -1.361 0.174
L1.Niederösterreich 0.247815 0.190953 1.298 0.194
L1.Oberösterreich -0.000199 0.166960 -0.001 0.999
L1.Salzburg 0.232594 0.088520 2.628 0.009
L1.Steiermark 0.122882 0.119234 1.031 0.303
L1.Tirol 0.074312 0.079702 0.932 0.351
L1.Vorarlberg 0.040446 0.072865 0.555 0.579
L1.Wien 0.266220 0.160262 1.661 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.592407 0.083564 7.089 0.000
L1.Burgenland -0.023054 0.043425 -0.531 0.595
L1.Kärnten -0.003127 0.036065 -0.087 0.931
L1.Niederösterreich -0.041194 0.100737 -0.409 0.683
L1.Oberösterreich 0.286623 0.088079 3.254 0.001
L1.Salzburg 0.017277 0.046698 0.370 0.711
L1.Steiermark 0.015848 0.062902 0.252 0.801
L1.Tirol 0.079624 0.042046 1.894 0.058
L1.Vorarlberg 0.137970 0.038440 3.589 0.000
L1.Wien -0.057654 0.084546 -0.682 0.495
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.145557 0.022261 0.209517 0.258126 0.072430 0.083493 -0.057041 0.170782
Kärnten 0.145557 1.000000 0.018892 0.193345 0.164398 -0.114111 0.168758 0.025135 0.313138
Niederösterreich 0.022261 0.018892 1.000000 0.306087 0.080185 0.220042 0.136511 0.052900 0.369584
Oberösterreich 0.209517 0.193345 0.306087 1.000000 0.296996 0.304582 0.107571 0.079948 0.132773
Salzburg 0.258126 0.164398 0.080185 0.296996 1.000000 0.154088 0.052683 0.083367 -0.018034
Steiermark 0.072430 -0.114111 0.220042 0.304582 0.154088 1.000000 0.112027 0.093790 -0.088272
Tirol 0.083493 0.168758 0.136511 0.107571 0.052683 0.112027 1.000000 0.161391 0.151397
Vorarlberg -0.057041 0.025135 0.052900 0.079948 0.083367 0.093790 0.161391 1.000000 0.075679
Wien 0.170782 0.313138 0.369584 0.132773 -0.018034 -0.088272 0.151397 0.075679 1.000000